<template>
  <div class="detail">
    <header @click="$router.back()">
      <van-icon name="arrow-left" />
    </header>
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="(item, index) in detail.pics2" :key="index">
        <img :src="item" alt="" />
      </van-swipe-item>
    </van-swipe>
    <div class="exp">
      <h5>{{ detail.basicInfo?.name }}</h5>
      <p>{{ detail.basicInfo?.characteristic }}</p>
      <section>
        <span class="lt">低价￥{{ detail.basicInfo?.minPrice }}</span>
        <span>原价￥{{ detail.basicInfo?.originalPrice }}</span>
        <span class="rt">库存{{ detail.basicInfo?.stores }}</span>
      </section>
    </div>
    <section class="tab">
      <span :class="{ active: tabIndex == 0 }" @click="tabIndex = 0">商品介绍</span>
      <span :class="{ active: tabIndex == 1 }" @click="tabIndex = 1">商品评价</span>
    </section>
    <div v-if="tabIndex == 0" v-html="detail.content"></div>
    <van-empty v-else description="描述文字" />
    <van-action-bar>
      <van-action-bar-icon icon="chat-o" text="客服" color="#ee0a24" />
      <van-action-bar-icon icon="cart-o" text="购物车" />
      <van-action-bar-icon icon="star" text="已收藏" color="#ff5000" />
      <van-action-bar-button type="warning" text="加入购物车" />
      <van-action-bar-button type="danger" text="立即购买" />
    </van-action-bar>
  </div>
</template>
<script>
import { getDetail } from "../../api/second/index.js";
import { useRoute } from "vue-router";
import { reactive, toRefs } from "vue";
export default {
  setup() {
    const { params } = useRoute();
    const data = reactive({
      detail: {}, // 详情的数据
      tabIndex: 0,
    });
    getDetail({ id: params.id }).then((res) => {
      data.detail = res.data;
    });

    return {
      ...toRefs(data),
    };
  },
};
</script>
<style lang="scss" scoped>
.detail {
  height: calc(100% - 50px);
  background: #e9e9e9;
  overflow: auto;
  .my-swipe {
    img {
      width: 100%;
      height: 375px;
    }
  }
  header {
    position: fixed;
    top: 10px;
    left: 10px;
    border-radius: 50%;
    border: 2px solid #fff;
    z-index: 99;
    padding: 2px;
    .van-badge__wrapper {
      background: #fff;
      border-radius: 50%;
    }
  }
  .exp {
    background: #fff;
    padding: 10px;
    box-sizing: border-box;
    font-size: 12px;
    color: #b8b8b8;
    margin-top: -2px;
    h5 {
      font-size: 15px;
      margin: 10px 0;
      color: #000;
    }
    section {
      margin-top: 10px;
      .rt {
        float: right;
      }
      .lt {
        color: red;
        font-size: 14px;
        margin-right: 10px;
      }
    }
  }
  .tab {
    height: 45px;
    display: flex;
    background: #fff;
    margin-top: 10px;
    span {
      width: 50%;
      text-align: center;
      line-height: 45px;
      border-bottom: 2px solid transparent;
      font-size: 16px;
    }
    .active {
      border-color: red;
    }
  }
}
</style>
